package com.ebspp.client.watcher;

import org.apache.thrift.server.TServer;
import org.apache.thrift.server.TThreadPoolServer;
import org.apache.thrift.transport.TServerSocket;
import org.apache.thrift.transport.TTransportException;

import com.ebspp.global.General;
import com.ebspp.server.WriteHandler;
import com.ebspp.thrift.DataWrite;
import com.ebspp.thrift.Watcher;

public class WatchServer
{
	public static void initServer()
	{
		try 
		{
			TServerSocket serverTransport = new TServerSocket(General.waPort);
			
			Watcher.Processor processor = new Watcher.Processor(new WatchHandler());

			TServer server = new TThreadPoolServer(
								new TThreadPoolServer.Args(serverTransport).processor(processor));
			/*
			TServer server = new TThreadPoolServer(
					new TThreadPoolServer.Args(serverTransport).processor(processor).
					protocolFactory(new TBinaryProtocol.Factory(true, true)));*/
			
			System.out.println("Start watcher at port: " + General.waPort);
			
			server.serve();
			System.err.println("Watcher server closed");
		} catch (TTransportException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
